import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.dialogs import Dialog, Messagebox
import tkinter as tk

class TestDialog(Dialog):
    """简单的测试对话框"""
    def __init__(self, parent):
        self.dialog_result = None
        super().__init__(parent, title="测试对话框")
        
    def body(self, master):
        """创建对话框内容"""
        frame = ttk.Frame(master, padding=10)
        frame.pack(fill=BOTH, expand=YES)
        
        ttk.Label(frame, text="测试对话框功能").pack(pady=10)
        self.text_var = ttk.StringVar(value="测试文本")
        ttk.Entry(frame, textvariable=self.text_var).pack(fill=X, pady=5)
        
        return frame
        
    def apply(self):
        """处理用户输入"""
        self.dialog_result = self.text_var.get()
        self.result = True
        print(f"对话框结果: {self.dialog_result}")

class TestApp:
    def __init__(self, root):
        self.root = root
        self.root.title("对话框测试")
        self.root.geometry("400x300")
        
        ttk.Button(root, text="打开对话框", command=self.open_dialog).pack(pady=20)
        
    def open_dialog(self):
        """打开测试对话框"""
        dialog = TestDialog(self.root)
        # 对话框关闭后检查结果
        if dialog.result:
            Messagebox.show_info(f"对话框返回: {getattr(dialog, 'dialog_result', None)}", "测试结果")
        else:
            Messagebox.show_info("对话框被取消", "测试结果")

if __name__ == "__main__":
    app = ttk.Window(themename="flatly")
    test_app = TestApp(app)
    app.mainloop()